package com.bwda.dsrs.systemservice.service.impl;

import com.bwda.dsrs.systemservice.domain.condition.verifycode.VerifyCodeCondition;
import com.bwda.dsrs.systemservice.domain.exception.SystemServiceException;
import com.bwda.dsrs.systemservice.domain.po.verifycode.VerifyCodePo;
import com.bwda.dsrs.systemservice.mapper.VerifyCodeMapper;
import com.bwda.dsrs.systemservice.service.VerifyCodeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yangjun
 */
@Service
public class VerifyCodeServiceImpl extends AbstractBaseServiceImpl<VerifyCodePo, VerifyCodeCondition, VerifyCodeMapper> implements VerifyCodeService {

    @Override
    public VerifyCodePo queryLastVerifyCode(String userCode) throws SystemServiceException{
        VerifyCodeCondition verifyCodeCondition = new VerifyCodeCondition();
        verifyCodeCondition.setUserCode(userCode);
        verifyCodeCondition.setPageNum(0);
        verifyCodeCondition.setPageSize(1);
        List<VerifyCodePo> list = this.getMapper().selectList(verifyCodeCondition);
        if (list.isEmpty()){
            throw new SystemServiceException("查询结果为空");
        }
        if(list.size()>1){
            throw new SystemServiceException("not unique");
        }
        return list.get(0);
    }
}